package com.training1.core.modules.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.training1.core.common.service.CrudService;
import com.training1.core.common.utils.excel.ExcelUtil;
import com.training1.core.entity.BatchWithDrawalEntity;
import com.training1.core.modules.dao.RemitSucDao;

@Service
@Transactional
public class RemitSucService extends CrudService<RemitSucDao, BatchWithDrawalEntity>  {
	/**
	 * 查询申请金额总额
	 * @return
	 */
	public BatchWithDrawalEntity findAllMoney(Map<String,Object> map) {
		return dao.findAllMoney(map);
	}

	public void export(List<BatchWithDrawalEntity> list, HttpServletResponse resp) {
		//设置列标题
		List<String> excelHead = new ArrayList<String>();
		excelHead.add("订单编号");
		excelHead.add("会员手机号");
		excelHead.add("打款(拒绝)时间");
		excelHead.add("银行");
		excelHead.add("卡号");
		excelHead.add("持卡人姓名");
		excelHead.add("预留手机号");
		excelHead.add("申请金额");	
				
		//设置内容		
		List<List<String>> dataList = new ArrayList<List<String>>();
		for (BatchWithDrawalEntity bde : list) {
			List<String> data = new ArrayList<String>();
			data.add(bde.getOrderNumber());
			data.add(bde.getPhone());
			
			Date date = bde.getPayTime();
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String dateString = formatter.format(date);
			data.add(dateString);
			
			data.add(bde.getBankforCard());
			data.add(bde.getCardNumber());
			data.add(bde.getName());
			data.add(bde.getCellphoneForCard());
			data.add(bde.getMoney().toString());
		
			dataList.add(data);
		}		
				
		//设置文件名
		String fileName;
		String sheetName = "sheet1";
		String titleName;
		fileName = "提现记录-已打款(拒绝)_"+new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		titleName = "提现记录—已打款(拒绝)列表";
		
		ExcelUtil.exportExcel(resp, excelHead, dataList, fileName, sheetName,titleName);
		
	}
}
